﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using JsonFx.Json;

public class AniEffect_AB : AniEffect {
	
	public class OBuff {
		
		public int id;
		
		public string name;
		
		public int round;
	}
	
	public virtual void play (OReportDetail detail, CallBack complete) {
		GameObject self = OReportEffect.forGameObject(detail.self);
		if(self != null) {
			try{
				OBuff buff = JsonReader.CoerceType(typeof(OBuff), detail.effectData) as OBuff;
				Object buffObject = Resources.Load("Effect_" + buff.name + "_AB");
				GameObject buffGameObject = AniEffectC.effectObject(buffObject, self, complete);
				Dictionary<int?, Dictionary<int?, GameObject>> aniEffectBuffDic = OReportEffect.Instance.aniEffectBuffDic;
				Dictionary<int?, GameObject> buffDic = null;
				aniEffectBuffDic.TryGetValue(detail.self, out buffDic);
				if(buffDic == null) {
					buffDic = new Dictionary<int?, GameObject>();
					aniEffectBuffDic.Add(detail.self, buffDic);
				}
				
				if(buffDic.ContainsKey(buff.id)) {
					complete();
					MonoBehaviour.Destroy(buffGameObject);
					
				} else {
					buffDic.Add(buff.id, buffGameObject);
				}
				
				return;

			} catch(System.Exception e) {
			}
		}
		
		complete();
	}
}
